<?php
class Admin_ContentController extends Zend_Controller_Action
{	
	
	public function indexAction()
	{	
		$task = $this->_helper->getHelper("TaskList");
		
		$service = new ContentService();
		$task->setService($service);
		
		$task->registerTask("search",'title');
		
		$data = $task->doTask();
		
		$gui = $this->_helper->getHelper("Gui");
		$gui->setToolbar(array('new','edit','delete'),My_Translate::translate("CONTENT_MANAGER"),"t_icon_article.png");
		$gui->showData($data);
		
		$categoryList = $service->loadCategoryOptions();
		$this->view->categoryList = $categoryList;
	}
	 
	
	public function createAction()
	{	
		$service = new ContentService();
		if ($this->getRequest()->isPost ()) {
			
			if($service->store())
			{
				$this->_redirect("/admin/content/index");exit;
			}
			else
			{
				$this->view->errorList = $service->getErrorMsg();
				$this->view->content = $_POST;
			}
		}
		else
		{
			$id = $this->_getParam("id");
			$title = My_Translate::translate("CONTENT_ADD");
			if(!empty($id))
			{
				$title = My_Translate::translate("CONTENT_EDIT");
				$this->view->content = $service->loadData($id);
			}
		}
		
		$this->view->categoryList = $service->loadCategoryOptions();;
		
		$gui = $this->_helper->getHelper("Gui");
		
		$gui->setToolbar(array('save','cancel'),$title,"t_icon_article.png");
	}
	
}
?>